<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ endNum }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'allList' }"
          href="javascript:;"
          @click="change('allList')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'NoDoneList' }"
          href="javascript:;"
          @click="change('NoDoneList')"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'DoneList' }"
          href="javascript:;"
          @click="change('DoneList')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="del">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },

  data() {
    return {
      type: "allList",
    };
  },

  methods: {
    change(type) {
      this.type = type;
      this.$emit("changeType", type);
    },

    del() {
      this.$emit("delDone");
    },
  },

  computed: {
    endNum() {
      return this.list.filter((item) => item.isDone).length;
    },
  },
};
</script>
